<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AppMenuModules
 * Indonesian Brains Solutions
 * @author macbook
 * E-mail : sony@sonywibisono.com
 */
class AppMenuModules {
    var $id;
    var $app_menu_id;
    var $app_module_id;
    var $visible;

    function __construct($id,$app_menu_id,$app_module_id,$visible) {
            $this->id=$id;
            $this->app_menu_id=$app_menu_id;
            $this->app_module_id=$app_module_id;
            $this->visible=$visible;
    }
    function open(){
        global $db;
        $sql="select * from app_menu_modules where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->app_menu_id=$app_menu_id;
            $this->app_module_id=$app_module_id;
            $this->visible=$visible;

        }
    }

    function openAll(){
        global $db;
        $sql="select * from app_menu_modules order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }
    function is_exist(){
        global $db;
        $sql="select id from app_menu_modules 
            where app_module_id={$this->app_module_id} and app_menu_id={$this->app_menu_id}";
        $result=$db->fetch_row($sql);
        if (!empty($result)){
            if ($result['id']>0){
                return TRUE;
            } else return FALSE;
        } else return FALSE;
    }
    function automatic_update(){
        if($this->is_exist()){
            $this->update();
        } else {
            $this->insert();
        }
    }
    function insert(){
    global $db;
    $sql="insert into app_menu_modules values (null,'{$this->app_menu_id}',
    '{$this->app_module_id}','{$this->visible}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update app_menu_modules set app_menu_id={$this->app_menu_id},
app_module_id={$this->app_module_id},
visible='{$this->visible}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from app_menu_modules where id=".$this->id;
        $db->query($sql);
    }

}
?>
